package com.aiyige.page.my.dynamicmanagement.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.os.Parcelable;
import android.support.v4.app.FragmentActivity;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.base.api.ApiManager;
import com.aiyige.base.api.ResponseCode;
import com.aiyige.base.api.apiengine.ActionEngine;
import com.aiyige.base.db.DBHelper;
import com.aiyige.base.db.dao.InfoModelDao;
import com.aiyige.base.db.dao.NormalVideoModelDao;
import com.aiyige.base.db.dao.PhotoModelDao;
import com.aiyige.base.db.dao.SpecialTopicDBModelDao;
import com.aiyige.base.db.dao.UploadFileDao;
import com.aiyige.base.db.table.InfoModel;
import com.aiyige.base.db.table.NormalVideoModel;
import com.aiyige.base.db.table.PhotoModel;
import com.aiyige.base.db.table.SpecialTopicDBModel;
import com.aiyige.base.eventbus.EventDeleteSearchMoment;
import com.aiyige.base.eventbus.EventEditInfoFinish;
import com.aiyige.base.eventbus.EventEditMajorCourseFinish;
import com.aiyige.base.eventbus.EventPublishProgressStatusUpdate;
import com.aiyige.model.moment.entity.Moment;
import com.aiyige.page.my.dynamicmanagement.DMPage;
import com.aiyige.page.publish.CommonTipDialog;
import com.aiyige.page.publish.info.model.PublishInfoFormModel;
import com.aiyige.page.publish.photo.model.PublishPhotoItem;
import com.aiyige.page.publish.util.PublishUtil;
import com.aiyige.track.TrackEvent;
import com.aiyige.utils.ColorUtil;
import com.aiyige.utils.DateFormatUtil;
import com.aiyige.utils.ErrorUtil;
import com.aiyige.utils.GlideUtil;
import com.aiyige.utils.ListUtil;
import com.aiyige.utils.MomentUtil;
import com.aiyige.utils.RetrofitUtil;
import com.aiyige.utils.SafeAsyncTask;
import com.aiyige.utils.StringUtils;
import com.aiyige.utils.ToastX;
import com.aiyige.utils.WebImageUrlModifier;
import com.aiyige.utils.widget.CommonBottomDialogFragment;
import com.aiyige.utils.widget.RoundCornerImageView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.j256.ormlite.misc.TransactionManager;
import com.j256.ormlite.stmt.UpdateBuilder;
import com.vondear.rxtools.RxTextTool;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.sql.SQLException;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.ResponseBody;
import retrofit2.Response;
import timber.log.Timber;

public class DMAdapter extends BaseQuickAdapter<MultiItemEntity, BaseViewHolder> {
    FragmentActivity mActivity;

    CommonBottomDialogFragment publishedNormalVideoDialog;
    CommonBottomDialogFragment rejectNormalVideoDialog;
    CommonBottomDialogFragment uploadingNormalVideoDialog;
    CommonBottomDialogFragment serverTranscodingNormalVideoDialog;

    CommonBottomDialogFragment publishedInfoDialog;
    CommonBottomDialogFragment notPublishedInfoDialog;
    CommonBottomDialogFragment rejectInfoDialog;
    CommonBottomDialogFragment uploadingInfoDialog;
    CommonBottomDialogFragment serverTranscodingInfoDialog;
    CommonBottomDialogFragment publishedInfoNoEditCopyDialog;
    CommonBottomDialogFragment notPublishedInfoNoEditCopyDialog;
    CommonBottomDialogFragment rejectInfoNoEditCopyDialog;

    CommonBottomDialogFragment publishedSpecialTopicDialog;
    CommonBottomDialogFragment notPublishedSpecialTopicDialog;
    CommonBottomDialogFragment rejectSpecialTopicDialog;
    CommonBottomDialogFragment uploadingSpecialTopicDialog;
    CommonBottomDialogFragment serverTranscodingSpecialTopicDialog;
    CommonBottomDialogFragment publishedSpecialTopicNoEditCopyDialog;
    CommonBottomDialogFragment notPublishedSpecialTopicNoEditCopyDialog;
    CommonBottomDialogFragment rejectSpecialTopicNoEditCopyDialog;

    CommonBottomDialogFragment publishedPhotoDialog;
    CommonBottomDialogFragment rejectPhotoDialog;
    CommonBottomDialogFragment uploadingPhotoDialog;


    EventBus eventBus;
    int currentPosition;
    TrackEvent trackEvent = new TrackEvent();
    Comparator<MultiItemEntity> comparator;
    boolean enableHighlight = false;

    public boolean isEnableHighlight() {
        return enableHighlight;
    }

    public void setEnableHighlight(boolean enableHighlight) {
        this.enableHighlight = enableHighlight;
    }

    public DMAdapter(FragmentActivity activity) {
        super(new LinkedList<MultiItemEntity>());
        this.mActivity = activity;
        eventBus = EventBus.builder().build();
        initInfoDialog();
        initNormalVideoDialog();
        initPhotoDialog();
        initSpecialTopicDialog();
        comparator = new Comparator<MultiItemEntity>() {
            @Override
            public int compare(MultiItemEntity o1, MultiItemEntity o2) {
                long o1ReleaseDate = 0;
                long o2ReleaseDate = 0;
                switch (o1.getItemType()) {
                    case PublishUtil.PARENT_TYPE_SPECIAL_TOPIC:
                        o1ReleaseDate = ((SpecialTopicDBModel) o1).getReleaseDate();
                        break;
                    case PublishUtil.PARENT_TYPE_NORMAL_VIDEO:
                        o1ReleaseDate = ((NormalVideoModel) o1).getReleaseDate();
                        break;
                    case PublishUtil.PARENT_TYPE_PHOTO:
                        o1ReleaseDate = ((PhotoModel) o1).getReleaseDate();
                        break;
                    case PublishUtil.PARENT_TYPE_INFO:
                        o1ReleaseDate = ((InfoModel) o1).getReleaseDate();
                        break;
                }
                switch (o2.getItemType()) {
                    case PublishUtil.PARENT_TYPE_SPECIAL_TOPIC:
                        o2ReleaseDate = ((SpecialTopicDBModel) o2).getReleaseDate();
                        break;
                    case PublishUtil.PARENT_TYPE_NORMAL_VIDEO:
                        o2ReleaseDate = ((NormalVideoModel) o2).getReleaseDate();
                        break;
                    case PublishUtil.PARENT_TYPE_PHOTO:
                        o2ReleaseDate = ((PhotoModel) o2).getReleaseDate();
                        break;
                    case PublishUtil.PARENT_TYPE_INFO:
                        o2ReleaseDate = ((InfoModel) o2).getReleaseDate();
                        break;
                }
                long diff = o2ReleaseDate - o1ReleaseDate;
                if (diff > 0) {
                    return 1;
                } else if (diff < 0) {
                    return -1;
                } else {
                    return 0;
                }
            }
        };
    }

    private void initPhotoDialog() {
        publishedPhotoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dmphoto_published_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn: {
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                            }
                        }
                    }
                })
                .build();
        uploadingPhotoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dmphoto_uploading_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn:
                                new DeleteLocalDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();
        rejectPhotoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dmphoto_reject_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn, R.id.rejectReasonBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                            case R.id.rejectReasonBtn:
                                try {
                                    String rejectReason = MomentUtil.extractRejectReason(((PhotoModel) getItem(position)).getRejectReason());
                                    CommonTipDialog.newInstance(rejectReason)
                                            .show(mActivity.getSupportFragmentManager(), "");
                                } catch (Exception e) {
                                }
                                break;
                        }
                    }
                })
                .build();
    }

    private void initSpecialTopicDialog() {
        publishedSpecialTopicDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_published_item_dialog)
                .viewIdList(R.id.editBtn, R.id.cancelPublishedBtn, R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.cancelPublishedBtn:
                                new CancelPublishTask(mActivity, position).execute();
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        publishedSpecialTopicNoEditCopyDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_published_item_no_edit_copy_dialog)
                .viewIdList(R.id.cancelPublishedBtn, R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.cancelPublishedBtn:
                                new CancelPublishTask(mActivity, position).execute();
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();


        notPublishedSpecialTopicDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_not_published_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.publishedBtn, R.id.editBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.publishedBtn: {
                                new SpecialTopicSubmitReviewTask(mActivity, position).execute();
                                break;
                            }

                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        notPublishedSpecialTopicNoEditCopyDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_not_published_item_no_edit_copy_dialog)
                .viewIdList(R.id.cancelBtn, R.id.publishedBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.publishedBtn: {
                                new SpecialTopicSubmitReviewTask(mActivity, position).execute();
                                break;
                            }

                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        serverTranscodingSpecialTopicDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_server_transcoding_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn: {
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                            }
                        }
                    }
                })
                .build();

        rejectSpecialTopicDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_reject_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.editBtn, R.id.rejectReasonBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.rejectReasonBtn:
                                try {
                                    String rejectReason = MomentUtil.extractRejectReason(((SpecialTopicDBModel) getItem(position)).getRejectReason());
                                    CommonTipDialog.newInstance(rejectReason)
                                            .show(mActivity.getSupportFragmentManager(), "");
                                } catch (Exception e) {
                                }
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        rejectSpecialTopicNoEditCopyDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_reject_item_no_edit_copy_dialog)
                .viewIdList(R.id.cancelBtn, R.id.rejectReasonBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.rejectReasonBtn:
                                try {
                                    String rejectReason = MomentUtil.extractRejectReason(((SpecialTopicDBModel) getItem(position)).getRejectReason());
                                    CommonTipDialog.newInstance(rejectReason)
                                            .show(mActivity.getSupportFragmentManager(), "");
                                } catch (Exception e) {
                                }
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        uploadingSpecialTopicDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_uploading_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn: {
                                new DeleteLocalDataTask(mActivity, position).execute();
                                break;
                            }
                        }
                    }
                }).build();
    }


    private void initInfoDialog() {
        publishedInfoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_published_item_dialog)
                .viewIdList(R.id.editBtn, R.id.cancelPublishedBtn, R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.cancelPublishedBtn:
                                new CancelPublishTask(mActivity, position).execute();
                                break;
                            case R.id.editBtn:
                                currentPosition = position;
                                registerGlobalEventBus();
                                new EditInfoTask(mActivity, position).execute();
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        publishedInfoNoEditCopyDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_published_item_no_edit_copy_dialog)
                .viewIdList(R.id.cancelPublishedBtn, R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.cancelPublishedBtn:
                                new CancelPublishTask(mActivity, position).execute();
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();


        notPublishedInfoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_not_published_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.publishedBtn, R.id.editBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.publishedBtn: {
                                new InfoSubmitReviewTask(mActivity, position).execute();
                                break;
                            }

                            case R.id.editBtn: {
                                currentPosition = position;
                                registerGlobalEventBus();
                                new EditInfoTask(mActivity, position).execute();
                                break;
                            }

                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        notPublishedInfoNoEditCopyDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_not_published_item_no_edit_copy_dialog)
                .viewIdList(R.id.cancelBtn, R.id.publishedBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.publishedBtn: {
                                new InfoSubmitReviewTask(mActivity, position).execute();
                                break;
                            }

                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        serverTranscodingInfoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_server_transcoding_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn: {
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                            }
                        }
                    }
                })
                .build();

        rejectInfoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_reject_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.editBtn, R.id.rejectReasonBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.editBtn:
                                currentPosition = position;
                                registerGlobalEventBus();
                                new EditInfoTask(mActivity, position).execute();
                                break;
                            case R.id.rejectReasonBtn:
                                try {
                                    String rejectReason = MomentUtil.extractRejectReason(((InfoModel) getItem(position)).getRejectReason());
                                    CommonTipDialog.newInstance(rejectReason)
                                            .show(mActivity.getSupportFragmentManager(), "");
                                } catch (Exception e) {
                                }
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        rejectInfoNoEditCopyDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_reject_item_no_edit_copy_dialog)
                .viewIdList(R.id.cancelBtn, R.id.rejectReasonBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.rejectReasonBtn:
                                try {
                                    String rejectReason = MomentUtil.extractRejectReason(((InfoModel) getItem(position)).getRejectReason());
                                    CommonTipDialog.newInstance(rejectReason)
                                            .show(mActivity.getSupportFragmentManager(), "");
                                } catch (Exception e) {
                                }
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        uploadingInfoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dminfo_uploading_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn: {
                                new DeleteLocalDataTask(mActivity, position).execute();
                                break;
                            }
                        }
                    }
                }).build();
    }


    private void initNormalVideoDialog() {
        publishedNormalVideoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dmnormal_video_published_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();

        rejectNormalVideoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dmnormal_video_reject_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.rejectReasonBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.rejectReasonBtn:
                                try {
                                    String rejectReason = MomentUtil.extractRejectReason(((NormalVideoModel) getItem(position)).getRejectReason());
                                    CommonTipDialog.newInstance(rejectReason)
                                            .show(mActivity.getSupportFragmentManager(), "");
                                } catch (Exception e) {
                                }
                                break;
                            case R.id.deleteBtn:
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                        }
                    }
                })
                .build();
        uploadingNormalVideoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dmnormal_video_uploading_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn: {
                                new DeleteLocalDataTask(mActivity, position).execute();
                                break;
                            }
                        }
                    }
                }).build();
        serverTranscodingNormalVideoDialog = CommonBottomDialogFragment.newBuilder()
                .layoutResId(R.layout.dmnormal_video_server_transcoding_item_dialog)
                .viewIdList(R.id.cancelBtn, R.id.deleteBtn)
                .listener(new CommonBottomDialogFragment.Listener() {
                    @Override
                    public void onViewClicked(int position, View view) {
                        switch (view.getId()) {
                            case R.id.deleteBtn: {
                                new DeleteServerDataTask(mActivity, position).execute();
                                break;
                            }
                        }
                    }
                })
                .build();

    }


    public EventBus getEventBus() {
        return eventBus;
    }

    public void registerGlobalEventBus() {
        try {
            EventBus.getDefault().register(this);
        } catch (Exception e) {

        }
    }

    public void unregisterGlobalEventBus() {
        try {
            EventBus.getDefault().unregister(this);
        } catch (Exception e) {

        }
    }

    @Override
    public void onViewAttachedToWindow(BaseViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        try {
            eventBus.register(holder);
        } catch (Exception e) {

        }
    }

    @Override
    public void onViewDetachedFromWindow(BaseViewHolder holder) {
        Timber.e("onViewDetachedFromWindow:");
        try {
            eventBus.unregister(holder);
        } catch (Exception e) {

        }
        super.onViewDetachedFromWindow(holder);
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder;
        switch (viewType) {
            case PublishUtil.PARENT_TYPE_INFO:
                baseViewHolder = new InfoViewHolder(getItemView(R.layout.dminfo_item, parent));
                break;
            case PublishUtil.PARENT_TYPE_NORMAL_VIDEO:
                baseViewHolder = new NormalVideoViewHolder(getItemView(R.layout.dmnormal_video_item, parent));
                break;
            case PublishUtil.PARENT_TYPE_PHOTO:
                baseViewHolder = new PhotoViewHolder(getItemView(R.layout.dmphoto_item, parent));
                break;
            case PublishUtil.PARENT_TYPE_SPECIAL_TOPIC:
                baseViewHolder = new SpecialTopicViewHolder(getItemView(R.layout.dmspecial_topic_item, parent));
                break;
            default:
                baseViewHolder = new BaseViewHolder(getItemView(R.layout.wild_card_item, parent));
                break;
        }
        return baseViewHolder;
    }

    @Override
    protected int getDefItemViewType(int position) {
        return getItem(position).getItemType();
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        switch (item.getItemType()) {
            case PublishUtil.PARENT_TYPE_INFO:
                ((InfoViewHolder) helper).bindData((InfoModel) item);
                break;
            case PublishUtil.PARENT_TYPE_SPECIAL_TOPIC:
                ((SpecialTopicViewHolder) helper).bindData((SpecialTopicDBModel) item);
                break;
            case PublishUtil.PARENT_TYPE_NORMAL_VIDEO:
                ((NormalVideoViewHolder) helper).bindData((NormalVideoModel) item);
                break;
            case PublishUtil.PARENT_TYPE_PHOTO:
                ((PhotoViewHolder) helper).bindData((PhotoModel) item);
                break;
        }
    }

    public class NormalVideoViewHolder extends BaseViewHolder {
        NormalVideoModel model;
        @BindView(R.id.releaseDateTv)
        TextView releaseDateTv;
        @BindView(R.id.moreBtn)
        ImageView moreBtn;
        @BindView(R.id.coverIv)
        RoundCornerImageView coverIv;
        @BindView(R.id.episodeTv)
        TextView episodeTv;
        @BindView(R.id.uploadStatusIv)
        ImageView uploadStatusIv;
        @BindView(R.id.uploadLayout)
        View uploadLayout;
        @BindView(R.id.coverLayout)
        FrameLayout coverLayout;
        @BindView(R.id.labelLeftView)
        View labelLeftView;
        @BindView(R.id.labelLeftIv)
        ImageView labelLeftIv;
        @BindView(R.id.labelTv)
        TextView labelTv;
        @BindView(R.id.titleTv)
        TextView titleTv;
        @BindView(R.id.statusTv)
        TextView statusTv;
        @BindView(R.id.watchNumTv)
        TextView watchNumTv;
        @BindView(R.id.watchNumLayout)
        LinearLayout watchNumLayout;
        @BindView(R.id.likeIv)
        ImageView likeIv;
        @BindView(R.id.likeTv)
        TextView likeTv;
        @BindView(R.id.commentIv)
        ImageView commentIv;
        @BindView(R.id.commentTv)
        TextView commentTv;
        @BindView(R.id.collectionIv)
        ImageView collectionIv;
        @BindView(R.id.collectionTv)
        TextView collectionTv;
        @BindView(R.id.countLayout)
        LinearLayout countLayout;
        int currentUploadImgResId = 0;

        public NormalVideoViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }


        public void bindData(NormalVideoModel data) {
            model = data;
            if (!TextUtils.isEmpty(data.getId())) {
                try {
                    NormalVideoModelDao.getDao().refresh(data);
                } catch (SQLException e) {
                    Timber.e("onEventPublishProgressStatusUpdate:" + Log.getStackTraceString(e));
                }
            }
            if (data.getControlOption() == PublishUtil.CONTROL_OPTION_DELETE) {
                remove(getAdapterPosition());
                return;
            }

            releaseDateTv.setText(DateFormatUtil.getStandardDate(data.getSellDate()));
            if (isEnableHighlight()) {
                titleTv.setText(Html.fromHtml(data.getTitle()));
            } else {
                titleTv.setText(data.getTitle());
            }
            watchNumTv.setText(StringUtils.formatNum(data.getViewCount()));
            likeTv.setText(StringUtils.formatNum(data.getLikeCount()));
            collectionTv.setText(StringUtils.formatNum(data.getCollectCount()));
            commentTv.setText(StringUtils.formatNum(data.getCommentCount()));
            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            if (currentUploadImgResId != R.drawable.upload) {
                                uploadStatusIv.setImageResource(R.drawable.upload);
                                currentUploadImgResId = R.drawable.upload;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                    }
                    uploadLayout.setVisibility(View.VISIBLE);
                    countLayout.setVisibility(View.GONE);
                    break;
                default:
                    uploadLayout.setVisibility(View.INVISIBLE);
                    countLayout.setVisibility(View.VISIBLE);
                    break;
            }

            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            statusTv.setText(R.string.not_published);
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            statusTv.setText(R.string.upload_failed_retry);
                            break;
                    }
                    break;
                case PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED:
                    statusTv.setText(R.string.not_published);
                    break;
                case PublishUtil.PROGRESS_STATUS_SERVER_TRANSCODING:
                    statusTv.setText(R.string.status_transcoding);
                    break;
                case PublishUtil.PROGRESS_STATUS_IN_REVIEW:
                    statusTv.setText(R.string.in_review);
                    break;
                case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                    statusTv.setText(R.string.published);
                    break;
                case PublishUtil.PROGRESS_STATUS_REJECT:
                    RxTextTool.getBuilder("")
                            .append(StringUtils.getString(R.string.reject)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_black_111111))
                            .append(StringUtils.getString(R.string.view_reason)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_red_fd5911))
                            .into(statusTv);
                    break;
            }
            GlideUtil.with(itemView.getContext())
                    .loadCover(data.getCoverUrl())
                    .into(coverIv);
        }

        @Subscribe(threadMode = ThreadMode.MAIN)
        public void onEventPublishProgressStatusUpdate(EventPublishProgressStatusUpdate event) {
            if (!TextUtils.isEmpty(model.getId())) {
                bindData(model);
            }
        }

        @OnClick({R.id.statusTv, R.id.moreBtn, R.id.uploadLayout})
        public void onViewClick(View view) {
            switch (view.getId()) {
                case R.id.statusTv: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_REJECT: {
                            try {
                                String rejectReason = MomentUtil.extractRejectReason(model.getRejectReason());
                                CommonTipDialog.newInstance(rejectReason)
                                        .show(mActivity.getSupportFragmentManager(), "");
                            } catch (Exception e) {
                            }
                            break;
                        }
                    }
                    break;
                }
                case R.id.uploadLayout: {
                    switch (model.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            UploadFileDao.resumeByParentId(model.getId());
                            NormalVideoModelDao.resumeById(model.getId());
                            bindData(model);
                            break;
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            UploadFileDao.pauseByParentId(model.getId());
                            NormalVideoModelDao.pauseById(model.getId());
                            bindData(model);
                            break;
                    }
                    break;
                }
                case R.id.moreBtn: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                        case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                        case PublishUtil.PROGRESS_STATUS_UPLOADING:
                        case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                        case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                        case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                            uploadingNormalVideoDialog.setPosition(getAdapterPosition());
                            uploadingNormalVideoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_SERVER_TRANSCODING:
                            serverTranscodingNormalVideoDialog.setPosition(getAdapterPosition());
                            serverTranscodingNormalVideoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                            publishedNormalVideoDialog.setPosition(getAdapterPosition());
                            publishedNormalVideoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_REJECT:
                            rejectNormalVideoDialog.setPosition(getAdapterPosition());
                            rejectNormalVideoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                    }
                    break;
                }
            }
        }

    }

    public class SpecialTopicViewHolder extends BaseViewHolder {
        SpecialTopicDBModel model;
        @BindView(R.id.releaseDateTv)
        TextView releaseDateTv;
        @BindView(R.id.moreBtn)
        ImageView moreBtn;
        @BindView(R.id.coverIv)
        RoundCornerImageView coverIv;
        @BindView(R.id.episodeTv)
        TextView episodeTv;
        @BindView(R.id.uploadStatusIv)
        ImageView uploadStatusIv;
        @BindView(R.id.uploadLayout)
        View uploadLayout;
        @BindView(R.id.coverLayout)
        FrameLayout coverLayout;
        @BindView(R.id.labelLeftView)
        View labelLeftView;
        @BindView(R.id.labelLeftIv)
        ImageView labelLeftIv;
        @BindView(R.id.labelTv)
        TextView labelTv;
        @BindView(R.id.titleTv)
        TextView titleTv;
        @BindView(R.id.statusTv)
        TextView statusTv;
        @BindView(R.id.watchNumTv)
        TextView watchNumTv;
        @BindView(R.id.watchNumLayout)
        LinearLayout watchNumLayout;
        @BindView(R.id.likeIv)
        ImageView likeIv;
        @BindView(R.id.likeTv)
        TextView likeTv;
        @BindView(R.id.commentIv)
        ImageView commentIv;
        @BindView(R.id.commentTv)
        TextView commentTv;
        @BindView(R.id.collectionIv)
        ImageView collectionIv;
        @BindView(R.id.collectionTv)
        TextView collectionTv;
        @BindView(R.id.countLayout)
        LinearLayout countLayout;
        int currentUploadImgResId = 0;

        public SpecialTopicViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(SpecialTopicDBModel data) {
            model = data;
            if (!TextUtils.isEmpty(data.getId())) {
                try {
                    SpecialTopicDBModelDao.getDao().refresh(data);
                } catch (SQLException e) {
                    Timber.e("onEventPublishProgressStatusUpdate:" + Log.getStackTraceString(e));
                }
            }
            if (data.getControlOption() == PublishUtil.CONTROL_OPTION_DELETE) {
                remove(getAdapterPosition());
                return;
            }

            releaseDateTv.setText(DateFormatUtil.getStandardDate(data.getSellDate()));
            if (isEnableHighlight()) {
                titleTv.setText(Html.fromHtml(data.getTitle()));
            } else {
                titleTv.setText(data.getTitle());
            }
            watchNumTv.setText(StringUtils.formatNum(data.getViewCount()));
            likeTv.setText(StringUtils.formatNum(data.getLikeCount()));
            collectionTv.setText(StringUtils.formatNum(data.getCollectCount()));
            commentTv.setText(StringUtils.formatNum(data.getCommentCount()));
            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            if (currentUploadImgResId != R.drawable.upload) {
                                uploadStatusIv.setImageResource(R.drawable.upload);
                                currentUploadImgResId = R.drawable.upload;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                    }
                    uploadLayout.setVisibility(View.VISIBLE);
                    countLayout.setVisibility(View.GONE);
                    break;
                default:
                    uploadLayout.setVisibility(View.INVISIBLE);
                    countLayout.setVisibility(View.VISIBLE);
                    break;
            }

            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            statusTv.setText(R.string.not_published);
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            statusTv.setText(R.string.upload_failed_retry);
                            break;
                    }
                    break;
                case PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED:
                    statusTv.setText(R.string.not_published);
                    break;
                case PublishUtil.PROGRESS_STATUS_SERVER_TRANSCODING:
                    statusTv.setText(R.string.status_transcoding);
                    break;
                case PublishUtil.PROGRESS_STATUS_IN_REVIEW:
                    statusTv.setText(R.string.in_review);
                    break;
                case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                    statusTv.setText(R.string.published);
                    break;
                case PublishUtil.PROGRESS_STATUS_REJECT:
                    RxTextTool.getBuilder("")
                            .append(StringUtils.getString(R.string.reject)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_black_111111))
                            .append(StringUtils.getString(R.string.view_reason)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_red_fd5911))
                            .into(statusTv);
                    break;
            }
            GlideUtil.with(itemView.getContext())
                    .loadCover(data.getCoverUrl())
                    .into(coverIv);
        }

        @Subscribe(threadMode = ThreadMode.MAIN)
        public void onEventPublishProgressStatusUpdate(EventPublishProgressStatusUpdate event) {
            if (!TextUtils.isEmpty(model.getId())) {
                bindData(model);
            }
        }

        @OnClick({R.id.statusTv, R.id.moreBtn, R.id.uploadLayout})
        public void onViewClick(View view) {
            switch (view.getId()) {
                case R.id.statusTv: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_REJECT: {
                            try {
                                String rejectReason = MomentUtil.extractRejectReason(model.getRejectReason());
                                CommonTipDialog.newInstance(rejectReason)
                                        .show(mActivity.getSupportFragmentManager(), "");
                            } catch (Exception e) {
                            }
                            break;
                        }
                    }
                    break;
                }

                case R.id.uploadLayout: {
                    switch (model.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            UploadFileDao.resumeByParentId(model.getId());
                            InfoModelDao.resumeById(model.getId());
                            bindData(model);
                            break;
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            UploadFileDao.pauseByParentId(model.getId());
                            InfoModelDao.pauseById(model.getId());
                            bindData(model);
                            break;
                    }
                    break;
                }
                case R.id.moreBtn: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                        case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                        case PublishUtil.PROGRESS_STATUS_UPLOADING:
                        case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                        case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                        case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                            uploadingSpecialTopicDialog.setPosition(getAdapterPosition());
                            uploadingSpecialTopicDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED:
                            switch (model.getPublishSource()) {
                                case PublishUtil.PUBLISH_SOURCE_ANDROID:
                                case PublishUtil.PUBLISH_SOURCE_IOS:
                                    notPublishedSpecialTopicDialog.setPosition(getAdapterPosition());
                                    notPublishedSpecialTopicDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                                default:
                                    notPublishedSpecialTopicNoEditCopyDialog.setPosition(getAdapterPosition());
                                    notPublishedSpecialTopicNoEditCopyDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                            }
                            break;
                        case PublishUtil.PROGRESS_STATUS_SERVER_TRANSCODING:
                            serverTranscodingSpecialTopicDialog.setPosition(getAdapterPosition());
                            serverTranscodingSpecialTopicDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                            switch (model.getPublishSource()) {
                                case PublishUtil.PUBLISH_SOURCE_ANDROID:
                                case PublishUtil.PUBLISH_SOURCE_IOS:
                                    publishedSpecialTopicDialog.setPosition(getAdapterPosition());
                                    publishedSpecialTopicDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                                default:
                                    publishedSpecialTopicNoEditCopyDialog.setPosition(getAdapterPosition());
                                    publishedSpecialTopicNoEditCopyDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                            }

                            break;
                        case PublishUtil.PROGRESS_STATUS_REJECT:
                            switch (model.getPublishSource()) {
                                case PublishUtil.PUBLISH_SOURCE_ANDROID:
                                case PublishUtil.PUBLISH_SOURCE_IOS:
                                    rejectSpecialTopicDialog.setPosition(getAdapterPosition());
                                    rejectSpecialTopicDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                                default:
                                    rejectSpecialTopicNoEditCopyDialog.setPosition(getAdapterPosition());
                                    rejectSpecialTopicNoEditCopyDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                            }
                            break;
                    }
                    break;
                }
            }
        }
    }

    public class InfoViewHolder extends BaseViewHolder {
        InfoModel model;
        @BindView(R.id.releaseDateTv)
        TextView releaseDateTv;
        @BindView(R.id.moreBtn)
        ImageView moreBtn;
        @BindView(R.id.coverIv)
        RoundCornerImageView coverIv;
        @BindView(R.id.episodeTv)
        TextView episodeTv;
        @BindView(R.id.uploadStatusIv)
        ImageView uploadStatusIv;
        @BindView(R.id.uploadLayout)
        View uploadLayout;
        @BindView(R.id.coverLayout)
        FrameLayout coverLayout;
        @BindView(R.id.labelLeftView)
        View labelLeftView;
        @BindView(R.id.labelLeftIv)
        ImageView labelLeftIv;
        @BindView(R.id.labelTv)
        TextView labelTv;
        @BindView(R.id.titleTv)
        TextView titleTv;
        @BindView(R.id.statusTv)
        TextView statusTv;
        @BindView(R.id.watchNumTv)
        TextView watchNumTv;
        @BindView(R.id.watchNumLayout)
        LinearLayout watchNumLayout;
        @BindView(R.id.likeIv)
        ImageView likeIv;
        @BindView(R.id.likeTv)
        TextView likeTv;
        @BindView(R.id.commentIv)
        ImageView commentIv;
        @BindView(R.id.commentTv)
        TextView commentTv;
        @BindView(R.id.collectionIv)
        ImageView collectionIv;
        @BindView(R.id.collectionTv)
        TextView collectionTv;
        @BindView(R.id.countLayout)
        LinearLayout countLayout;
        int currentUploadImgResId = 0;

        public InfoViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(InfoModel data) {
            model = data;
            if (!TextUtils.isEmpty(data.getId())) {
                try {
                    InfoModelDao.getDao().refresh(data);
                } catch (SQLException e) {
                    Timber.e("onEventPublishProgressStatusUpdate:" + Log.getStackTraceString(e));
                }
            }
            if (data.getControlOption() == PublishUtil.CONTROL_OPTION_DELETE) {
                remove(getAdapterPosition());
                return;
            }

            releaseDateTv.setText(DateFormatUtil.getStandardDate(data.getSellDate()));
            if (isEnableHighlight()) {
                titleTv.setText(Html.fromHtml(data.getTitle()));
            } else {
                titleTv.setText(data.getTitle());
            }
            watchNumTv.setText(StringUtils.formatNum(data.getViewCount()));
            likeTv.setText(StringUtils.formatNum(data.getLikeCount()));
            collectionTv.setText(StringUtils.formatNum(data.getCollectCount()));
            commentTv.setText(StringUtils.formatNum(data.getCommentCount()));
            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            if (currentUploadImgResId != R.drawable.upload) {
                                uploadStatusIv.setImageResource(R.drawable.upload);
                                currentUploadImgResId = R.drawable.upload;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                    }
                    uploadLayout.setVisibility(View.VISIBLE);
                    countLayout.setVisibility(View.GONE);
                    break;
                default:
                    uploadLayout.setVisibility(View.INVISIBLE);
                    countLayout.setVisibility(View.VISIBLE);
                    break;
            }

            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            statusTv.setText(R.string.not_published);
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            statusTv.setText(R.string.upload_failed_retry);
                            break;
                    }
                    break;
                case PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED:
                    statusTv.setText(R.string.not_published);
                    break;
                case PublishUtil.PROGRESS_STATUS_SERVER_TRANSCODING:
                    statusTv.setText(R.string.status_transcoding);
                    break;
                case PublishUtil.PROGRESS_STATUS_IN_REVIEW:
                    statusTv.setText(R.string.in_review);
                    break;
                case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                    statusTv.setText(R.string.published);
                    break;
                case PublishUtil.PROGRESS_STATUS_REJECT:
                    RxTextTool.getBuilder("")
                            .append(StringUtils.getString(R.string.reject)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_black_111111))
                            .append(StringUtils.getString(R.string.view_reason)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_red_fd5911))
                            .into(statusTv);
                    break;
            }
            GlideUtil.with(itemView.getContext())
                    .loadCover(data.getCoverUrl())
                    .into(coverIv);
        }

        @Subscribe(threadMode = ThreadMode.MAIN)
        public void onEventPublishProgressStatusUpdate(EventPublishProgressStatusUpdate event) {
            if (!TextUtils.isEmpty(model.getId())) {
                bindData(model);
            }
        }

        @OnClick({R.id.statusTv, R.id.moreBtn, R.id.uploadLayout})
        public void onViewClick(View view) {
            switch (view.getId()) {
                case R.id.statusTv: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_REJECT: {
                            try {
                                String rejectReason = MomentUtil.extractRejectReason(model.getRejectReason());
                                CommonTipDialog.newInstance(rejectReason)
                                        .show(mActivity.getSupportFragmentManager(), "");
                            } catch (Exception e) {
                            }
                            break;
                        }
                    }
                    break;
                }

                case R.id.uploadLayout: {
                    switch (model.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            UploadFileDao.resumeByParentId(model.getId());
                            InfoModelDao.resumeById(model.getId());
                            bindData(model);
                            break;
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            UploadFileDao.pauseByParentId(model.getId());
                            InfoModelDao.pauseById(model.getId());
                            bindData(model);
                            break;
                    }
                    break;
                }
                case R.id.moreBtn: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                        case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                        case PublishUtil.PROGRESS_STATUS_UPLOADING:
                        case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                        case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                        case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                            uploadingInfoDialog.setPosition(getAdapterPosition());
                            uploadingInfoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED:
                            switch (model.getPublishSource()) {
                                case PublishUtil.PUBLISH_SOURCE_ANDROID:
                                case PublishUtil.PUBLISH_SOURCE_IOS:
                                    notPublishedInfoDialog.setPosition(getAdapterPosition());
                                    notPublishedInfoDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                                default:
                                    notPublishedInfoNoEditCopyDialog.setPosition(getAdapterPosition());
                                    notPublishedInfoNoEditCopyDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                            }
                            break;
                        case PublishUtil.PROGRESS_STATUS_SERVER_TRANSCODING:
                            serverTranscodingInfoDialog.setPosition(getAdapterPosition());
                            serverTranscodingInfoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                            switch (model.getPublishSource()) {
                                case PublishUtil.PUBLISH_SOURCE_ANDROID:
                                case PublishUtil.PUBLISH_SOURCE_IOS:
                                    publishedInfoDialog.setPosition(getAdapterPosition());
                                    publishedInfoDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                                default:
                                    publishedInfoNoEditCopyDialog.setPosition(getAdapterPosition());
                                    publishedInfoNoEditCopyDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                            }

                            break;
                        case PublishUtil.PROGRESS_STATUS_REJECT:
                            switch (model.getPublishSource()) {
                                case PublishUtil.PUBLISH_SOURCE_ANDROID:
                                case PublishUtil.PUBLISH_SOURCE_IOS:
                                    rejectInfoDialog.setPosition(getAdapterPosition());
                                    rejectInfoDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                                default:
                                    rejectInfoNoEditCopyDialog.setPosition(getAdapterPosition());
                                    rejectInfoNoEditCopyDialog.show(mActivity.getSupportFragmentManager(), "");
                                    break;
                            }
                            break;
                    }
                    break;
                }
            }
        }
    }

    public class PhotoViewHolder extends BaseViewHolder {
        PhotoModel model;
        @BindView(R.id.releaseDateTv)
        TextView releaseDateTv;
        @BindView(R.id.moreBtn)
        ImageView moreBtn;
        @BindView(R.id.coverIv)
        RoundCornerImageView coverIv;
        @BindView(R.id.episodeTv)
        TextView episodeTv;
        @BindView(R.id.uploadStatusIv)
        ImageView uploadStatusIv;
        @BindView(R.id.uploadLayout)
        View uploadLayout;
        @BindView(R.id.coverLayout)
        FrameLayout coverLayout;
        @BindView(R.id.labelLeftView)
        View labelLeftView;
        @BindView(R.id.labelLeftIv)
        ImageView labelLeftIv;
        @BindView(R.id.labelTv)
        TextView labelTv;
        @BindView(R.id.titleTv)
        TextView titleTv;
        @BindView(R.id.statusTv)
        TextView statusTv;
        @BindView(R.id.watchNumTv)
        TextView watchNumTv;
        @BindView(R.id.watchNumLayout)
        LinearLayout watchNumLayout;
        @BindView(R.id.likeIv)
        ImageView likeIv;
        @BindView(R.id.likeTv)
        TextView likeTv;
        @BindView(R.id.commentIv)
        ImageView commentIv;
        @BindView(R.id.commentTv)
        TextView commentTv;
        @BindView(R.id.collectionIv)
        ImageView collectionIv;
        @BindView(R.id.collectionTv)
        TextView collectionTv;
        @BindView(R.id.countLayout)
        LinearLayout countLayout;
        int currentUploadImgResId = 0;

        public PhotoViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(PhotoModel data) {
            model = data;
            if (!TextUtils.isEmpty(data.getId())) {
                try {
                    PhotoModelDao.getDao().refresh(data);
                } catch (SQLException e) {
                    Timber.e("onEventPublishProgressStatusUpdate:" + Log.getStackTraceString(e));
                }
            }
            if (data.getControlOption() == PublishUtil.CONTROL_OPTION_DELETE) {
                remove(getAdapterPosition());
                return;
            }

            releaseDateTv.setText(DateFormatUtil.getStandardDate(data.getSellDate()));
            if (isEnableHighlight()) {
                titleTv.setText(Html.fromHtml(data.getTitle()));
            } else {
                titleTv.setText(data.getTitle());
            }
            watchNumTv.setText(StringUtils.formatNum(data.getViewCount()));
            likeTv.setText(StringUtils.formatNum(data.getLikeCount()));
            collectionTv.setText(StringUtils.formatNum(data.getCollectCount()));
            commentTv.setText(StringUtils.formatNum(data.getCommentCount()));
            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            if (currentUploadImgResId != R.drawable.upload) {
                                uploadStatusIv.setImageResource(R.drawable.upload);
                                currentUploadImgResId = R.drawable.upload;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            if (currentUploadImgResId != R.drawable.suspend) {
                                uploadStatusIv.setImageResource(R.drawable.suspend);
                                currentUploadImgResId = R.drawable.suspend;
                            }
                            break;
                    }
                    uploadLayout.setVisibility(View.VISIBLE);
                    countLayout.setVisibility(View.GONE);
                    break;
                default:
                    uploadLayout.setVisibility(View.INVISIBLE);
                    countLayout.setVisibility(View.VISIBLE);
                    break;
            }

            switch (data.getProgressStatus()) {
                case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                case PublishUtil.PROGRESS_STATUS_UPLOADING:
                case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                    switch (data.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            statusTv.setText(R.string.not_published);
                            break;
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                            statusTv.setText(R.string.upload_failed_retry);
                            break;
                    }
                    break;
                case PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED:
                    statusTv.setText(R.string.not_published);
                    break;
                case PublishUtil.PROGRESS_STATUS_SERVER_TRANSCODING:
                    statusTv.setText(R.string.status_transcoding);
                    break;
                case PublishUtil.PROGRESS_STATUS_IN_REVIEW:
                    statusTv.setText(R.string.in_review);
                    break;
                case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                    statusTv.setText(R.string.published);
                    break;
                case PublishUtil.PROGRESS_STATUS_REJECT:
                    RxTextTool.getBuilder("")
                            .append(StringUtils.getString(R.string.reject)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_black_111111))
                            .append(StringUtils.getString(R.string.view_reason)).setForegroundColor(ColorUtil.getColor(R.color.zwcolor_red_fd5911))
                            .into(statusTv);
                    break;
            }
            List<PublishPhotoItem> publishPhotoItemList = new LinkedList<>();
            try {
                publishPhotoItemList = JSON.parseArray(model.getCover(), PublishPhotoItem.class);
            } catch (Exception e) {
            }
            GlideUtil.with(itemView.getContext())
                    .loadCover(ListUtil.isEmpty(publishPhotoItemList) ? "" : publishPhotoItemList.get(0).getPhotoUrl())
                    .into(coverIv);
        }

        @Subscribe(threadMode = ThreadMode.MAIN)
        public void onEventPublishProgressStatusUpdate(EventPublishProgressStatusUpdate event) {
            if (!TextUtils.isEmpty(model.getId())) {
                bindData(model);
            }
        }

        @OnClick({R.id.statusTv, R.id.moreBtn, R.id.uploadLayout})
        public void onViewClick(View view) {
            switch (view.getId()) {
                case R.id.statusTv: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_REJECT: {
                            try {
                                String rejectReason = MomentUtil.extractRejectReason(model.getRejectReason());
                                CommonTipDialog.newInstance(rejectReason)
                                        .show(mActivity.getSupportFragmentManager(), "");
                            } catch (Exception e) {
                            }
                            break;
                        }
                    }
                    break;
                }
                case R.id.uploadLayout: {
                    switch (model.getControlOption()) {
                        case PublishUtil.CONTROL_OPTION_FAILED_PAUSE:
                        case PublishUtil.CONTROL_OPTION_PAUSE:
                            UploadFileDao.resumeByParentId(model.getId());
                            PhotoModelDao.resumeById(model.getId());
                            bindData(model);
                            break;
                        case PublishUtil.CONTROL_OPTION_UPLOAD:
                            UploadFileDao.pauseByParentId(model.getId());
                            PhotoModelDao.pauseById(model.getId());
                            bindData(model);
                            break;
                    }
                    break;
                }
                case R.id.moreBtn: {
                    switch (model.getProgressStatus()) {
                        case PublishUtil.PROGRESS_STATUS_NEED_TRANSCODE:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FINISH:
                        case PublishUtil.PROGRESS_STATUS_TRANSCODE_FAILED:
                        case PublishUtil.PROGRESS_STATUS_WAITING_UPLOAD:
                        case PublishUtil.PROGRESS_STATUS_UPLOADING:
                        case PublishUtil.PROGRESS_STATUS_UPLOAD_FINISH:
                        case PublishUtil.PROGRESS_STATUS_SUBMITTING:
                        case PublishUtil.PROGRESS_STATUS_SUBMIT_FAILED:
                            uploadingPhotoDialog.setPosition(getAdapterPosition());
                            uploadingPhotoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_PUBLISHED:
                            publishedPhotoDialog.setPosition(getAdapterPosition());
                            publishedPhotoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                        case PublishUtil.PROGRESS_STATUS_REJECT:
                            rejectPhotoDialog.setPosition(getAdapterPosition());
                            rejectPhotoDialog.show(mActivity.getSupportFragmentManager(), "");
                            break;
                    }
                    break;
                }
            }
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(EventEditInfoFinish event) {
        if (getItem(currentPosition).getItemType() == PublishUtil.PARENT_TYPE_INFO) {
            if (event.getResultCode() == EventEditMajorCourseFinish.RESULT_OK) {
                setData(currentPosition, event.getInfoModel());
                sortData();
                notifyDataSetChanged();
            }
        }
        unregisterGlobalEventBus();
    }

    public void sortData() {
        Collections.sort(getData(), comparator);
    }

    public class EditInfoTask extends SafeAsyncTask<Object, Object, Object> {
        int position;

        public EditInfoTask(Activity activity, int position) {
            super(activity, R.string.text_process);
            this.position = position;
        }


        @Override
        protected Object doInBackground(Object... objects) {
            try {
                InfoModel infoModel = (InfoModel) getItem(position);
                String goodsId = infoModel.getGoodsId();
                Response<ResponseBody> response = ApiManager.getService().getMoment(goodsId).execute();
                if (response.code() != ResponseCode.OK) {
                    throw new Exception(ErrorUtil.extractMessageFromErrorResponse(response));
                }
                String json = RetrofitUtil.getResponseBodyAsString(response);
                Moment moment = new Moment(JSON.parseObject(json, Moment.class));
                return PublishInfoFormModel.parse(moment, PublishUtil.OPERATION_TYPE_EDIT);
            } catch (Exception e) {
                return e;
            }
        }

        @Override
        public void safeOnPostExecute(Object o) {
            if (o instanceof Exception) {
                ToastX.show(((Exception) o).getMessage());
            } else if (o instanceof PublishInfoFormModel) {
                ARouter.getInstance()
                        .build(ARouterConfig.PublishInfoPage)
                        .withParcelable("formModel", (Parcelable) o)
                        .navigation(getActivity(), DMPage.REQUEST_CODE_PUBLISH);
            } else {
                ToastX.show(R.string.unknown_error);
            }
        }
    }

    public class DeleteLocalDataTask extends SafeAsyncTask<Object, Object, Object> {
        int position;

        public DeleteLocalDataTask(Activity activity, int position) {
            super(activity);
            this.position = position;
        }

        @Override
        protected Object doInBackground(Object... objects) {
            try {
                MultiItemEntity multiItemEntity = getItem(position);
                switch (multiItemEntity.getItemType()) {
                    case PublishUtil.PARENT_TYPE_INFO: {
                        final InfoModel infoModel = (InfoModel) multiItemEntity;
                        TransactionManager.callInTransaction(DBHelper.getInstance().getConnectionSource(), new Callable<Object>() {
                            @Override
                            public Object call() throws Exception {
                                UploadFileDao.deleteByParentId(infoModel.getId());
                                InfoModelDao.deleteById(infoModel.getId());
                                return null;
                            }
                        });
                        break;
                    }
                    case PublishUtil.PARENT_TYPE_PHOTO: {
                        final PhotoModel photoModel = (PhotoModel) multiItemEntity;
                        TransactionManager.callInTransaction(DBHelper.getInstance().getConnectionSource(), new Callable<Object>() {
                            @Override
                            public Object call() throws Exception {
                                UploadFileDao.deleteByParentId(photoModel.getId());
                                PhotoModelDao.deleteById(photoModel.getId());
                                return null;
                            }
                        });
                        break;
                    }
                    case PublishUtil.PARENT_TYPE_NORMAL_VIDEO: {
                        final NormalVideoModel normalVideoModel = (NormalVideoModel) multiItemEntity;
                        TransactionManager.callInTransaction(DBHelper.getInstance().getConnectionSource(), new Callable<Object>() {
                            @Override
                            public Object call() throws Exception {
                                UploadFileDao.deleteByParentId(normalVideoModel.getId());
                                NormalVideoModelDao.deleteById(normalVideoModel.getId());
                                return null;
                            }
                        });
                        break;
                    }
                    default:
                        throw new Exception(StringUtils.getString(R.string.unknown_error));
                }
                return null;
            } catch (Exception e) {
                return e;
            }
        }


        @Override
        public void safeOnPostExecute(Object o) {
            if (o instanceof Exception) {
                ToastX.show((Exception) o);
            } else {
                remove(position);
            }
        }
    }

    public class CancelPublishTask extends SafeAsyncTask<Object, Object, Object> {
        int position;
        MultiItemEntity multiItemEntity;

        public CancelPublishTask(Activity activity, int positon) {
            super(activity, R.string.text_process);
            this.position = positon;
            multiItemEntity = getItem(position);
        }

        @Override
        protected Object doInBackground(Object... objects) {
            try {
                String goodsId;
                switch (multiItemEntity.getItemType()) {
                    case PublishUtil.PARENT_TYPE_SPECIAL_TOPIC:
                        goodsId = ((SpecialTopicDBModel) multiItemEntity).getGoodsId();
                        break;
                    case PublishUtil.PARENT_TYPE_INFO:
                        goodsId = ((InfoModel) multiItemEntity).getGoodsId();
                        break;
                    case PublishUtil.PARENT_TYPE_NORMAL_VIDEO:
                        goodsId = ((NormalVideoModel) multiItemEntity).getGoodsId();
                        break;
                    case PublishUtil.PARENT_TYPE_PHOTO:
                        goodsId = ((PhotoModel) multiItemEntity).getGoodsId();
                        break;
                    default:
                        throw new Exception(StringUtils.getString(R.string.unknown_error));
                }

                Moment moment = new Moment();
                moment.setId(goodsId);
                Response<ResponseBody> response = ApiManager.getService().changeMomentStatus(moment.getId(), ActionEngine.GET_OFF, moment).execute();
                if (response.code() != ResponseCode.CREATED) {
                    throw new Exception(ErrorUtil.extractMessageFromErrorResponse(response));
                }
                return null;
            } catch (Exception e) {
                return e;
            }
        }

        @Override
        public void safeOnPostExecute(Object o) {
            if (o instanceof Exception) {
                ToastX.show((Exception) o);
            } else {
                switch (multiItemEntity.getItemType()) {
                    case PublishUtil.PARENT_TYPE_SPECIAL_TOPIC: {
                        SpecialTopicDBModel specialTopicDBModel = (SpecialTopicDBModel) multiItemEntity;
                        specialTopicDBModel.setProgressStatus(PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED);
                        try {
                            SpecialTopicDBModelDao.getDao().update(specialTopicDBModel);
                        } catch (Exception e) {
                        }
                        setData(position, specialTopicDBModel);
                        break;
                    }


                    case PublishUtil.PARENT_TYPE_INFO: {
                        InfoModel infoModel = (InfoModel) multiItemEntity;
                        infoModel.setProgressStatus(PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED);
                        try {
                            InfoModelDao.getDao().update(infoModel);
                        } catch (Exception e) {
                        }
                        setData(position, infoModel);
                        break;
                    }
                    case PublishUtil.PARENT_TYPE_PHOTO: {
                        PhotoModel photoModel = (PhotoModel) multiItemEntity;
                        photoModel.setProgressStatus(PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED);
                        try {
                            PhotoModelDao.getDao().update(photoModel);
                        } catch (Exception e) {
                        }
                        setData(position, photoModel);
                        break;
                    }
                    case PublishUtil.PARENT_TYPE_NORMAL_VIDEO: {
                        NormalVideoModel normalVideoModel = (NormalVideoModel) multiItemEntity;
                        normalVideoModel.setProgressStatus(PublishUtil.PROGRESS_STATUS_NOT_PUBLISHED);
                        try {
                            NormalVideoModelDao.getDao().update(normalVideoModel);
                        } catch (Exception e) {
                        }
                        setData(position, normalVideoModel);
                        break;
                    }
                }
            }
        }
    }


    public class DeleteServerDataTask extends SafeAsyncTask<Object, Object, Object> {
        int position;
        String goodsId;
        EventDeleteSearchMoment eventDeleteSearchMoment;

        public DeleteServerDataTask(Activity activity, int position) {
            super(activity, R.string.text_process);
            this.position = position;
        }

        @Override
        protected Object doInBackground(Object... objects) {
            try {
                MultiItemEntity multiItemEntity = getItem(position);
                Response<ResponseBody> response;
                switch (multiItemEntity.getItemType()) {
                    case PublishUtil.PARENT_TYPE_SPECIAL_TOPIC: {
                        goodsId = ((SpecialTopicDBModel) multiItemEntity).getGoodsId();
                        eventDeleteSearchMoment = EventDeleteSearchMoment.newBuilder()
                                .serverId(goodsId)
                                .parentType(PublishUtil.PARENT_TYPE_SPECIAL_TOPIC)
                                .build();
                        break;
                    }

                    case PublishUtil.PARENT_TYPE_INFO: {
                        goodsId = ((InfoModel) multiItemEntity).getGoodsId();
                        eventDeleteSearchMoment = EventDeleteSearchMoment.newBuilder()
                                .serverId(goodsId)
                                .parentType(PublishUtil.PARENT_TYPE_INFO)
                                .build();
                        break;
                    }
                    case PublishUtil.PARENT_TYPE_PHOTO: {
                        goodsId = ((PhotoModel) multiItemEntity).getGoodsId();
                        eventDeleteSearchMoment = EventDeleteSearchMoment.newBuilder()
                                .serverId(goodsId)
                                .parentType(PublishUtil.PARENT_TYPE_PHOTO)
                                .build();
                        break;
                    }
                    case PublishUtil.PARENT_TYPE_NORMAL_VIDEO: {
                        goodsId = ((NormalVideoModel) multiItemEntity).getGoodsId();
                        eventDeleteSearchMoment = EventDeleteSearchMoment.newBuilder()
                                .serverId(goodsId)
                                .parentType(PublishUtil.PARENT_TYPE_NORMAL_VIDEO)
                                .build();
                        break;
                    }
                    default:
                        throw new Exception(StringUtils.getString(R.string.unknown_error));
                }
                response = ApiManager.getService().deleteMoment(goodsId).execute();
                if (response.code() != ResponseCode.NO_CONTENT) {
                    throw new Exception(ErrorUtil.extractMessageFromErrorResponse(response));
                }
                return null;
            } catch (Exception e) {
                return e;
            }
        }


        @Override
        public void safeOnPostExecute(Object o) {
            if (o instanceof Exception) {
                ToastX.show((Exception) o);
            } else {
                remove(position);
                if (eventDeleteSearchMoment != null) {
                    EventBus.getDefault().post(eventDeleteSearchMoment);
                }
            }
        }
    }

    public class InfoSubmitReviewTask extends SafeAsyncTask<Object, Object, Object> {
        int position;
        InfoModel infoModel;

        public InfoSubmitReviewTask(Activity activity, int position) {
            super(activity, R.string.text_process);
            this.position = position;
            infoModel = (InfoModel) getItem(position);
        }

        @Override
        protected Object doInBackground(Object... objects) {
            try {
                String goodsId = infoModel.getGoodsId();
                Moment moment = new Moment();
                moment.setId(goodsId);
                Response<ResponseBody> response = ApiManager.getService()
                        .changeMomentStatus(moment.getId(), ActionEngine.PUT_ON, moment)
                        .execute();
                if (response.code() != ResponseCode.CREATED) {
                    throw new Exception(ErrorUtil.extractMessageFromErrorResponse(response));
                }
                return null;
            } catch (Exception e) {
                return e;
            }
        }

        @Override
        public void safeOnPostExecute(Object o) {
            if (o instanceof Exception) {
                ToastX.show((Exception) o);
            } else {
                try {
                    try {
                        UpdateBuilder<InfoModel, String> updateBuilder = InfoModelDao.getDao().updateBuilder();
                        updateBuilder.updateColumnValue(InfoModel.PROGRESS_STATUS, PublishUtil.PROGRESS_STATUS_PUBLISHED);
                        updateBuilder.where().eq(InfoModel.ID, infoModel.getId());
                        updateBuilder.update();
                    } catch (Exception e) {
                    }
                    infoModel.setProgressStatus(PublishUtil.PROGRESS_STATUS_PUBLISHED);
                    setData(position, infoModel);
                } catch (Exception e) {
                }
            }
        }
    }


    public class SpecialTopicSubmitReviewTask extends SafeAsyncTask<Object, Object, Object> {
        int position;
        SpecialTopicDBModel specialTopicDBModel;

        public SpecialTopicSubmitReviewTask(Activity activity, int position) {
            super(activity, R.string.text_process);
            this.position = position;
            specialTopicDBModel = (SpecialTopicDBModel) getItem(position);
        }

        @Override
        protected Object doInBackground(Object... objects) {
            try {
                String goodsId = specialTopicDBModel.getGoodsId();
                Moment moment = new Moment();
                moment.setId(goodsId);
                Response<ResponseBody> response = ApiManager.getService()
                        .changeMomentStatus(moment.getId(), ActionEngine.PUT_ON, moment)
                        .execute();
                if (response.code() != ResponseCode.CREATED) {
                    throw new Exception(ErrorUtil.extractMessageFromErrorResponse(response));
                }
                return null;
            } catch (Exception e) {
                return e;
            }
        }

        @Override
        public void safeOnPostExecute(Object o) {
            if (o instanceof Exception) {
                ToastX.show((Exception) o);
            } else {
                try {
                    try {
                        UpdateBuilder<SpecialTopicDBModel, String> updateBuilder = SpecialTopicDBModelDao.getDao().updateBuilder();
                        updateBuilder.updateColumnValue(SpecialTopicDBModel.PROGRESS_STATUS, PublishUtil.PROGRESS_STATUS_PUBLISHED);
                        updateBuilder.where().eq(SpecialTopicDBModel.ID, specialTopicDBModel.getId());
                        updateBuilder.update();
                    } catch (Exception e) {
                    }
                    specialTopicDBModel.setProgressStatus(PublishUtil.PROGRESS_STATUS_PUBLISHED);
                    setData(position, specialTopicDBModel);
                } catch (Exception e) {
                }
            }
        }
    }


}
